package com.example.common;

import com.example.jedis.JedisClusterConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author kangshuai
 */
@Service
public class RedisClientTemplate {

    @Autowired
    private JedisClusterConfig jedisClusterConfig;

    public boolean setToRedis(String key,Object value){
        try {
            String str=jedisClusterConfig.getJedisCluster().set(key, String.valueOf(value));
            if("OK".equals(str)) {
                System.out.println("setToRedis:{Key:" + key + ",value" + value + "},保存成功！");
                return true;
            }
        }catch (Exception ex){
            System.out.println("setToRedis:{Key:"+key+",value"+value+"}");
        }
        return false;
    }

    public Object getRedis(String key){
        String str=null;
        try {
            str=jedisClusterConfig.getJedisCluster().get(key);
            System.out.println("getRedis:{Key:"+key+"}，查询成功！");
        }catch (Exception ex){
            System.out.println("getRedis:{Key:"+key+"}");
        }
        return str;
    }

}
